@{ViewBag.Title = "Paging";}
@section CssImport{<link href="@Url.Content("~/Scripts/validationEngine/validationEngine.jquery.css")" rel="stylesheet" type="text/css" />}
@section JavascriptImport{
<script type="text/javascript" src="@Url.Content("~/Scripts/validationEngine/jquery.validationEngine.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/validationEngine/jquery.validationEngine-en.js")"></script>}
<div class="filtering"><form>
<label>Introduzca texto para filtrar: <input type="text" name="filter" id="filter" /></label>
<button type="submit" id="LoadRecordsButton" class="button medium orange" >Buscar Coincidencias</button>
</form></div>
<div id="MyTableContainer"></div>
<script type="text/javascript">
     $(document).ready(function () {
     $('#MyTableContainer').jtable({
         title: 'AIT_Lote',
         paging: true,
         pageSize: 10,
         sorting: true,
         defaultSorting: 'Id ASC',
         actions: {
             listAction: '@Url.Action("JSONPagedListByFilter")',
             deleteAction: '@Url.Action("JSONDelete")',
             updateAction: '@Url.Action("JSONUpdate")',
             createAction: '@Url.Action("JSONCreate")'
         },
         fields:
         {
          Id: {
                 key: true,
                 create: false,
                 edit: false,
                 list: false
             }
             ,
             Codigo: {
                 title: 'Codigo',
                 create: false,
                 edit: false,
                 list: true,
                 sorting: false
             }
             ,
             CodSecuencia: {
                 title: 'CodSecuencia',
                 create: true,
                 edit: true,
                 list: true,
                 sorting: false
             }
             ,
             Descripcion: {
                 title:'Descripcion',
                 create: true,
                 edit: true,
                 list: true,
                 sorting: false
             }
             ,  
             FechaRegistro: {                 
                 type: 'hidden'                 
             }
             ,
             FechaIngreso: {
                 title:'FechaIngreso',
                 create: true,
                 edit: true,
                 list: true,
                 type: 'date',
                 displayFormat: 'dd-mm-yy',
                 sorting: false
             }
             ,
             RegistradoPor: {
                 title: 'RegistradoPor',
                 create: false,
                 edit: false,
                 list: true,
                 sorting: false
             }
             ,
             EquiposLote: {
                 title: 'Equipos IT',
                 width: '5%',
                 sorting: false,
                 edit: false,
                 create: false,
                 listClass: 'child-opener-image-column',
                 display: function (loteData) {
                     var $img = $('<img class="child-opener-image" with="20" height="20" src="../../Content/images/home.png" title="Gestiona Equipos de este Lote" />');
                     //Open child table when user clicks the image
                     $img.click(function () {
                         $('#MyTableContainer').jtable('openChildTable',
                                    $img.closest('tr'),
                                    {
                                        title: 'Equipos del Lote : ' + loteData.record.Descripcion,
                                        actions: {
                                            listAction: '@Url.Action("../AIT_EquipoIT/EquiposDeLote")?LoteId=' + loteData.record.Id,
                                            deleteAction: '@Url.Action("../AIT_EquipoIT/JSONDelete")',
                                            updateAction: '@Url.Action("../AIT_EquipoIT/JSONUpdate")',
                                            createAction: '@Url.Action("../AIT_EquipoIT/JSONCreate")'
                                        },
                                        fields: {
                                            LoteId_FK: {
                                                type: 'hidden',
                                                defaultValue: loteData.record.Id
                                            }
                                            ,
                                            Id: {
                                                key: true,
                                                create: false,
                                                edit: false,
                                                list: false
                                            }
                                            ,
                                            Codigo: {
                                                title: 'Codigo',
                                                create: true,
                                                edit: true,
                                                list: true,
                                                sorting: false
                                            }
                                            ,
                                            CodigoSerialNumber: {
                                                title: 'CodigoSerialNumber',
                                                create: true,
                                                edit: true,
                                                list: true,
                                                inputClass: 'validate[required]',
                                                sorting: false
                                            }
                                            ,
                                            NumFactura: {
                                                title: 'NumFactura',
                                                create: true,
                                                edit: true,
                                                list: true,
                                                sorting: false
                                            }
                                            ,
                                            Descripcion: {
                                                title: 'Descripcion',
                                                create: true,
                                                edit: true,
                                                list: true,
                                                sorting: false
                                            }
                                            ,
                                            EsEquipoCompuesto: {
                                                title: 'EsEquipoCompuesto',
                                                create: true,
                                                edit: true,
                                                list: true,
                                                type: 'checkbox',
                                                values: { 'false': 'Es equipo Nuevo', 'true': 'Compuesto' },
                                                sorting: false
                                            }
                                            ,
                                            FechaRegistro: {
                                                title: 'FechaRegistro',
                                                create: true,
                                                edit: true,
                                                list: true,
                                                type: 'date',
                                                displayFormat: 'dd-mm-yy',
                                                sorting: false
                                            }
                                            ,
                                            ModeloEquipoId_FK: {
                                                title: 'AIT_ModeloEquipo',
                                                create: true,
                                                edit: true,
                                                list: true,
                                                options: '@Url.Action("../AIT_ModeloEquipo/JSONGetElementsForDropDownList")'
                                            }
                                            ,
                                            TipoEquipoId_FK: {
                                                title: 'AIT_TipoEquipo',
                                                create: true,
                                                edit: true,
                                                list: true,
                                                options: '@Url.Action("../AIT_TipoEquipo/JSONGetElementsForDropDownList")'
                                            }  
                                        }
                                    }, function (data) { //opened handler
                                        data.childTable.jtable('load');
                                    });
                     });
                     //Return image to show on the person row
                     return $img;
                 }
             }  











},
formCreated: function (event, data) {data.form.validationEngine();},
formSubmitting: function (event, data) {return data.form.validationEngine('validate');},
formClosed: function (event, data) { data.form.validationEngine('hide'); data.form.validationEngine('detach'); }
});
$('#LoadRecordsButton').click(function (e) {e.preventDefault();$('#MyTableContainer').jtable('load', {filter: $('#filter').val()});});
$('#LoadRecordsButton').click();
});
</script>

